package liming.ai.data.deepseek;

import liming.ai.data.AbstractRequest;
import org.json.JSONArray;
import org.json.JSONObject;

public class ChatCompletionRequest implements AbstractRequest {
    private final JSONArray messages = new JSONArray();
    private static final String model = "deepseek-reasoner";
    
    public void addMessage(Message message) {
        messages.put(message.toJson());
    }

    public JSONObject toJson() {
        JSONObject json = new JSONObject();
        json.put("model", model);
        json.put("messages", messages);
        json.put("stream", true); // 保持流式传输
        json.put("max_tokens", 8*1024);
        return json;
    }

    @Override
    public String getBody() {
        return toJson().toString();
    }

    @Override
    public void clear() {
        messages.clear();
    }

    @Override
    public JSONObject getLastMessage() {
        return (JSONObject)messages.remove(messages.length() - 1);
    }

    @Override
    public JSONArray getMessages() {
        return messages;
    }

    @Override
    public String toString() {
        return "ChatCompletionRequest{" +
                "messages=" + messages +
                '}';
    }
}